package cn.edu.javaweb.userServlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import cn.edu.javaweb.utils.DBUtil;

@WebServlet("/RegisterServlet")
public class RegisterServlet extends HttpServlet {
	DBUtil db;
	private static final long serialVersionUID = 1L;
       
    
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name = request.getParameter("name");
		String uclass = request.getParameter("uclass");
		String password = request.getParameter("password");
		String telephone = request.getParameter("telephone");
		String sex = request.getParameter("sex");
		String ident = request.getParameter("ident");
		System.out.println(name);
		db = new DBUtil();
		//初始化
		//db.init();
		String SQL="insert into examine(name,uclass,password,telephone,sex,ident) values('"+name+"','"+uclass+"','"+password+"','"+telephone+"','"+sex +"','"+ident+"')";
		System.out.println(SQL);
		int result=db.update(SQL); 
		System.out.println(SQL);
		response.setContentType("text/html;charset=utf-8");
	    PrintWriter out=response.getWriter();
	    if(result>0)
	    	out.println("<script>alert('信息已提交请等待审核！！！');window.location.href='volunteer/Login&Register.jsp'</script>;");
	    else
	    	out.println("插入失败！");
	}

}
